09 / 12

What is an <iframe> used for?

Using the <iframe> Element

The <iframe> (inline frame) element in HTML is used to embed another HTML document within the current page. It creates a rectangular frame where the external content is displayed.

Key Points about <iframe>
  1. 1

    It allows embedding entire web pages, maps, videos, or other content from external sources.

  2. 2

    Common uses include embedding YouTube videos, Google Maps, or widgets from other sites.

  3. 3

    Attributes include src (URL to embed), width, height, title (for accessibility), and sandbox (for security).

  4. 4

    The allowfullscreen attribute enables full-screen mode for videos.

  5. 5

    The loading="lazy" attribute defers loading until the iframe is visible, improving page performance.

Example Usage

In short: <iframe> is used to display external web content within your page while keeping it separate from your main HTML structure.